<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('人才库列表')" />
	<style type="text/css">
		label.layui-form-label {width: 95px;padding-right: 0px;}
		.listext th,.listext td{border:solid 1px #ddd;text-align:left;padding:10px;font-size:14px;}
		#importProgress {z-index:20200202;background-color: #000;opacity: 0.3;display:none;}
		.importProgress {width:300px;z-index:20202222;position: fixed;top: 34%;left: 40%;display:none;}

		#lightbox_mask{display: none;position: fixed;z-index: 19891016;left: 0;top: 0;width: 100%;height: 100%;background-color: rgba(0, 0, 0, .7);}
		#showpic{position: fixed;z-index: 19891017;left: 0;top: 0;width: 100%;height: 100%;text-align:center;padding-top: 0.5%;}
		#dp{width: 30%;margin:auto}
		#viewCard{width: 300px;background: #fff;margin:6% auto;padding:30px 0 40px 0;border-radius: 10px;position:relative;overflow: hidden;box-shadow: 5px 5px 50px #000;}

	</style>
</head>
<body>
<form>
	<div class="layuiadmin-header-box">
		<th:block th:include="listinclude :: searchTop" />
	</div>
</form>
<div class="mid-content">
	<table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
</div>
<div id="iTable" class="display_no">
	<table class="importTable listext" data-resizable-columns-id="demo-table">
		<tbody id="itbody">
		</tbody>
	</table>
</div>
<!-- 导入进度条 -->
<div id="importProgress" class="layui-layer-shade">
</div>
<div class="importProgress">
	<div class="layui-progress layui-progress-big" lay-showpercent="true" lay-filter="dhprogress">
		<div class="layui-progress-bar layui-bg-blue" lay-percent="0%"></div>
	</div>
</div>
<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
		<div class="layui-btn layui-btn-normal layui-table-tools" lay-event="addbtn" shiro:hasPermission="hr:talentpool:add">
			<p class="dhicon dh-plus" style="color:white;font-size:14px"><span class="fa_span">新增</span></p>
		</div>
		<div class="layui-btn layui-btn-danger layui-table-tools" onclick="remove()" shiro:hasPermission="hr:talentpool:delete">
			<p class="dhicon dh-remove" style="color:white;font-size:14px"><span class="fa_span">批量删除</span></p>
		</div>
		<div class="layui-btn layui-table-tools importbtn-bg" lay-event="importBtn" shiro:hasPermission="hr:talentpool:import">
			<i class="dhicon dh-upload"></i> 导入
		</div>
		<div class="layui-btn layui-table-tools importbtn-bg" lay-event="exportbtn" shiro:hasPermission="hr:talentpool:export">
			<i class="dhicon dh-download"></i> 导出
		</div>
	</div>
</script>
<script type="text/html" id="barDh">
	<a class="layui-btn layui-btn-xs dhicon dh-edit" onclick="$.operate.edit('{{d.guid}}')" shiro:hasPermission="hr:talentpool:edit">&nbsp;修改</a>
	<a class="layui-btn layui-btn-danger layui-btn-xs dhicon dh-remove" onclick="remove('{{d.guid}}')" shiro:hasPermission="hr:talentpool:delete">&nbsp;删除</a>
</script>
<!-- 人才库导入区域 -->
<script type="text/template" id="importTpl">
	<form enctype="multipart/form-data" class="mt20 mb10">
		<div class="col-xs-offset-1">
			<input type="file" id="file" name="file"/>
			<div class="mt10 pt5">
				<a onclick="$.tablelist.importTemplate('/hr/talentpool/exporttemplate')" class="btn btn-default btn-xs"><i class="dhicon dh-file-excel-o"></i> 下载模板</a>
			</div>
			<font color="red" class="pull-left mt10">
				提示：仅允许导入“xls”或“xlsx”格式文件！
			</font>
		</div>
	</form>
</script>
<th:block th:include="include :: footer" />
<th:block th:include="include :: businessJS" />
<script th:inline="javascript">
	/*<![CDATA[*/
	var prefix = ctx + "hr/talentpool";
	var gridColumns = [[${gridColumns}]],
			importFields =[[${importFields}]],
			moduleTable =[[${moduleTable}]];
	/*]]>*/
</script>
<script type="text/javascript">
	var fieldWidth = {},		//导入列表字段宽度
			filedRequired = {},		//导入列表必填字段
			hasNull = false;		//导入数据必填字段有空值
	var dateFiled = [];	//导入列表日期字段
	$.each(gridColumns.dictionaryForPageFieldList,function(i,v){
		fieldWidth[v.fields] = v.fieldFrontWidth
		if(v.fieldFrontRequired)filedRequired[v.fields] = v.fieldName;
		if(v.fieldFrontType == 't_date')dateFiled.push(v.fields);
	})
	var $,layer,form,table,element,thStr,wherestr={};
	layui.use(['jquery','layer','form','table','element'], function () {
		$ = layui.$, layer = layui.layer, form = layui.form, table = layui.table, element = layui.element;
		$.tablelist.init({
			elem: '#dhtable'
			,url: prefix + '/list'
			,modalName: "人才库"
			,updateUrl: prefix + "/edit?guid={id}"
			,totalRow: gridColumns.totalRow
			,cols: [gridColumns.gridBody
			]
			,toolbar: '#toolbar'
			,defaultToolbar: [{title:'列设置',layEvent: 'fieldSet',icon: 'layui-icon-set'}] //这里在右边显示
			,height:'full-85'
		});
		//监听排序事件
		table.on('sort(ftable)', function(obj){
			$.tablelist.sort('dhtable',obj);
		});
		//头工具栏事件
		table.on('toolbar(ftable)', function(obj){
			switch(obj.event){
				case 'addbtn':
					top.layui.index.openTabsPage(prefix+ "/add",'人才库 - 新增')
					break;
				case 'exportbtn':
					$.ajax({
						url: '/hr/talentpool/export',
						type: 'GET',
						data: getWherestr(),
						dataType: 'json',
						beforeSend: function(){
							showloadings(true);
						},
						success: function(result){
							if (result.code == 0) {
								window.location.href = ctx + "common/download?fileName=" + encodeURIComponent(result.msg) + "&delete=" + true;
							} else if (result.code == web_status.WARNING) {
								$.modal.alertWarning(result.msg)
							} else {
								$.modal.alertError(result.msg);
							}
							showloadings(false);
						}
					});
					break;
				
			case 'tableFull'://表格展开
				$('.north .layui-form').hide();
				table.reload('dhtable',{
					defaultToolbar: [{title:'收缩',layEvent:'tableShrink',icon:'layui-icon-screen-restore'}],
					height: $(window).height()-$('.north').height()-60<300?'300':$(window).height()-( $('.north').height()+$('.south').height()+12)
				});
			break;
			case 'tableShrink'://表格收缩
				$('.north .layui-form').show();
				table.reload('dhtable',{
					defaultToolbar: [{title:'展开',layEvent:'tableFull',icon:'layui-icon-screen-full'}],
					height: $(window).height()-$('.north').height()-60<300?'300':$(window).height()-( $('.north').height()+$('.south').height()+12)
				});
			break;
	    	case 'importBtn':
					thStr = '<tr><th><div style="width:30px;">序号</div></th>'
					$.each(importFields,function(i,val){
						thStr += '<th><div style="width:'+fieldWidth[val]+'px;">' + i + '</div></th>';
					})
					thStr += '</tr>';
					layer.open({
						type: 1,
						area: ['400px', '230px'],
						fix: false,
						offset: '10%',
						maxmin: true,
						shade: 0.3,
						title: '导入人才库',
						content: $('#importTpl').html(),
						btn: ['<i class="dhicon dh-check"></i> 导入', '<i class="dhicon dh-remove"></i> 取消'],
						shadeClose: true,
						zIndex: 1000,
						btn1: function(index, layero){
							var file = layero.find('#file');
							if(!file[0]['value']){
								layer.msg("请选择文件！");
								return false;
							}
							var imRes = importListExcel(file[0], importFields, 'talentpool');
						}
					});
					break;
				case 'fieldSet':
					filedSet(moduleTable);
					break;
			};
		});
		//搜索按钮
		$('#btn-search').on('click', function () {
			$.each(wherestr,function(i,v){$("#"+i).val()?wherestr[i]=$("#"+i).val():wherestr[i]='';});//动态获取条件的值
			table.reload('dhtable', {page: {curr: 1},where:wherestr});
		});
		//监听下拉框——添加条件
		form.on('select(fft)', function(obj){
			addMore(this);
		});
	});
	//通过guid彻底删除
	function remove(guid){
		if(guid){
			$.operate.remove("该删除无法恢复，请确认？",prefix + "/delete/",{'talentPoolItems':JSON.stringify([{'guid':guid}])},function(result){
				allReload(result)
			});
		}else{
			if(table.checkStatus('dhtable').data.length>0){
				$.operate.remove("是否彻底删除该"+table.checkStatus('dhtable').data.length+"条产品？",prefix + "/delete/",{'talentPoolItems':JSON.stringify(table.checkStatus('dhtable').data, null, 2)},function(result){
					allReload(result)
				});
			}else{
				layer.msg("无勾选数据！");
			};
		}
	}
	//刷新
	function allReload(result){
		if(result.code==0){
			setTimeout(function(){
				layer.closeAll();
				table.reload('dhtable');
			}, 1000);
		}
	}
	/*批量请求导入数据
     *tobj：导入数据对象
     *startNum：从第几条开始导入
     *oneImportNum：每次导入条数
     *allImportNum：总数据量
     *times：导入次数
     */
	function eachImport(tobj,startNum, oneImportNum, allImportNum, times, timeNum){
		var importObj = [], inum = startNum, importBl='0%';
		for(var i = startNum; i < startNum + oneImportNum; i++){
			if(i >= allImportNum)break;
			inum = i + 1 ;
			importObj.push(tobj[i]);
		}
		$.ajaxSettings.async = false;
		$.post("/hr/talentpool/addpost", {'talentPoolItems':JSON.stringify(importObj, null, 2)}, function(result) {
			importBl = (inum/allImportNum)*100;
			console.log('导入比:'+importBl.toFixed(2)+ '%');
			console.log('数量:'+inum);
			console.log('总次数:'+times);
			console.log('当前次数:'+timeNum);
			importObj = [];
			timeNum += 1;
			res = result;
		},"json");
		setTimeout(function(){
			if(timeNum <= times){
				eachImport(tobj, startNum + oneImportNum, oneImportNum, allImportNum, times, timeNum);
			}else{
				element.progress('dhprogress', importBl.toFixed(2)+ '%');
				showloadings(false);
				closeProcess(res, 'talentpool');
			}
			element.progress('dhprogress', importBl.toFixed(2)+ '%');
		},500);
	}
</script>
</body>
</html>